Author: rscheff
Date: Sat Oct 24 20:23:20 2020
New Revision: 367017
URL: https://svnweb.freebsd.org/changeset/base/367017

Log:
  MFC r366569: Add IP(V6)_VLAN_PCP to set 802.1 priority per-flow.
  
  This adds a new IP_PROTO / IPV6_PROTO setsockopt (getsockopt)
  option IP(V6)_VLAN_PCP, which can be set to -1 (interface
  default), or explicitly to any priority between 0 and 7.
  
  Note that for untagged traffic, explicitly adding a
  priority will insert a special 801.1Q vlan header with
  vlan ID = 0 to carry the priority setting
  
  Reviewed by:  gallatin, rrs
  MFC after:    2 weeks
  Sponsored by: NetApp, Inc.
  Differential Revision:        https://reviews.freebsd.org/D26409

Modified:
  stable/12/sys/net/if_ethersubr.c
  stable/12/sys/netinet/in.h
  stable/12/sys/netinet/in_pcb.h
  stable/12/sys/netinet/ip_output.c
  stable/12/sys/netinet6/in6.h
  stable/12/sys/netinet6/ip6_output.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/net/if_ethersubr.c
==============================================================================
--- stable/12/sys/net/if_ethersubr.c    Sat Oct 24 20:09:27 2020        
(r367016)
+++ stable/12/sys/net/if_ethersubr.c    Sat Oct 24 20:23:20 2020        
(r367017)
@@ -1349,6 +1349,13 @@ ether_8021q_frame(struct mbuf **mp, struct ifnet *ife,
        }
 
        /*
+        * If PCP is set in mbuf, use it
+        */
+       if ((*mp)->m_flags & M_VLANTAG) {
+               pcp = EVL_PRIOFTAG((*mp)->m_pkthdr.ether_vtag);
+       }
+
+       /*
         * If underlying interface can do VLAN tag insertion itself,
         * just pass the packet along. However, we need some way to
         * tell the interface where the packet came from so that it

Modified: stable/12/sys/netinet/in.h
==============================================================================
--- stable/12/sys/netinet/in.h  Sat Oct 24 20:09:27 2020        (r367016)
+++ stable/12/sys/netinet/in.h  Sat Oct 24 20:23:20 2020        (r367017)
@@ -483,6 +483,10 @@ __END_DECLS
 /* The following option is private; do not use it from user applications. */
 #define        IP_MSFILTER                     74   /* set/get filter list */
 
+/* The following option deals with the 802.1Q Ethernet Priority Code Point */
+#define        IP_VLAN_PCP             75   /* int; set/get PCP used for 
packet, */
+                                    /*      -1 use interface default */
+
 /* Protocol Independent Multicast API [RFC3678] */
 #define        MCAST_JOIN_GROUP                80   /* join an any-source 
group */
 #define        MCAST_LEAVE_GROUP               81   /* leave all sources for 
group */

Modified: stable/12/sys/netinet/in_pcb.h
==============================================================================
--- stable/12/sys/netinet/in_pcb.h      Sat Oct 24 20:09:27 2020        
(r367016)
+++ stable/12/sys/netinet/in_pcb.h      Sat Oct 24 20:23:20 2020        
(r367017)
@@ -762,6 +762,13 @@ int        inp_so_options(const struct inpcb *inp);
 #define INP_SUPPORTS_MBUFQ     0x00004000 /* Supports the mbuf queue method of 
LRO */
 #define INP_MBUF_QUEUE_READY   0x00008000 /* The transport is pacing, inputs 
can be queued */
 #define INP_DONT_SACK_QUEUE    0x00010000 /* If a sack arrives do not wake me 
*/
+#define INP_2PCP_SET           0x00020000 /* If the Eth PCP should be set 
explicitly */
+#define INP_2PCP_BIT0          0x00040000 /* Eth PCP Bit 0 */
+#define INP_2PCP_BIT1          0x00080000 /* Eth PCP Bit 1 */
+#define INP_2PCP_BIT2          0x00100000 /* Eth PCP Bit 2 */
+#define INP_2PCP_BASE  INP_2PCP_BIT0
+#define INP_2PCP_MASK  (INP_2PCP_BIT0 | INP_2PCP_BIT1 | INP_2PCP_BIT2)
+#define INP_2PCP_SHIFT         18         /* shift PCP field in/out of 
inp_flags2 */
 /*
  * Flags passed to in_pcblookup*() functions.
  */

Modified: stable/12/sys/netinet/ip_output.c
==============================================================================
--- stable/12/sys/netinet/ip_output.c   Sat Oct 24 20:09:27 2020        
(r367016)
+++ stable/12/sys/netinet/ip_output.c   Sat Oct 24 20:23:20 2020        
(r367017)
@@ -61,7 +61,9 @@ __FBSDID("$FreeBSD$");
 
 #include <net/if.h>
 #include <net/if_var.h>
+#include <net/if_vlan_var.h>
 #include <net/if_llatbl.h>
+#include <net/ethernet.h>
 #include <net/netisr.h>
 #include <net/pfil.h>
 #include <net/route.h>
@@ -221,6 +223,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct rou
        int hlen = sizeof (struct ip);
        int mtu;
        int error = 0;
+       int vlan_pcp = -1;
        struct sockaddr_in *dst;
        const struct sockaddr_in *gw;
        struct in_ifaddr *ia;
@@ -241,6 +244,9 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct rou
                        m->m_pkthdr.flowid = inp->inp_flowid;
                        M_HASHTYPE_SET(m, inp->inp_flowtype);
                }
+               if ((inp->inp_flags2 & INP_2PCP_SET) != 0)
+                       vlan_pcp = (inp->inp_flags2 & INP_2PCP_MASK) >>
+                           INP_2PCP_SHIFT;
        }
 
        if (ro == NULL) {
@@ -588,6 +594,9 @@ sendit:
                }
        }
 
+       if (vlan_pcp > -1)
+               EVL_APPLY_PRI(m, vlan_pcp);
+
        /* IN_LOOPBACK must not appear on the wire - RFC1122. */
        if (IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) ||
            IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) {
@@ -1087,6 +1096,7 @@ ip_ctloutput(struct socket *so, struct sockopt *sopt)
 #ifdef RSS
                case IP_RECVRSSBUCKETID:
 #endif
+               case IP_VLAN_PCP:
                        error = sooptcopyin(sopt, &optval, sizeof optval,
                                            sizeof optval);
                        if (error)
@@ -1182,6 +1192,28 @@ ip_ctloutput(struct socket *so, struct sockopt *sopt)
                                OPTSET2(INP_RECVRSSBUCKETID, optval);
                                break;
 #endif
+                       case IP_VLAN_PCP:
+                               if ((optval >= -1) && (optval <=
+                                   (INP_2PCP_MASK >> INP_2PCP_SHIFT))) {
+                                       if (optval == -1) {
+                                               INP_WLOCK(inp);
+                                               inp->inp_flags2 &=
+                                                   ~(INP_2PCP_SET |
+                                                     INP_2PCP_MASK);
+                                               INP_WUNLOCK(inp);
+                                       } else {
+                                               INP_WLOCK(inp);
+                                               inp->inp_flags2 |=
+                                                   INP_2PCP_SET;
+                                               inp->inp_flags2 &=
+                                                   ~INP_2PCP_MASK;
+                                               inp->inp_flags2 |=
+                                                   optval << INP_2PCP_SHIFT;
+                                               INP_WUNLOCK(inp);
+                                       }
+                               } else
+                                       error = EINVAL;
+                               break;
                        }
                        break;
 #undef OPTSET
@@ -1302,6 +1334,7 @@ ip_ctloutput(struct socket *so, struct sockopt *sopt)
                case IP_RSSBUCKETID:
                case IP_RECVRSSBUCKETID:
 #endif
+               case IP_VLAN_PCP:
                        switch (sopt->sopt_name) {
 
                        case IP_TOS:
@@ -1389,6 +1422,14 @@ ip_ctloutput(struct socket *so, struct sockopt *sopt)
 #endif
                        case IP_BINDMULTI:
                                optval = OPTBIT2(INP_BINDMULTI);
+                               break;
+                       case IP_VLAN_PCP:
+                               if (OPTBIT2(INP_2PCP_SET)) {
+                                       optval = (inp->inp_flags2 &
+                                           INP_2PCP_MASK) >> INP_2PCP_SHIFT;
+                               } else {
+                                       optval = -1;
+                               }
                                break;
                        }
                        error = sooptcopyout(sopt, &optval, sizeof optval);

Modified: stable/12/sys/netinet6/in6.h
==============================================================================
--- stable/12/sys/netinet6/in6.h        Sat Oct 24 20:09:27 2020        
(r367016)
+++ stable/12/sys/netinet6/in6.h        Sat Oct 24 20:23:20 2020        
(r367017)
@@ -510,6 +510,10 @@ struct route_in6 {
                                    * set/get multicast source filter list.
                                    */
 
+/* The following option deals with the 802.1Q Ethernet Priority Code Point */
+#define        IPV6_VLAN_PCP           75  /* int; set/get PCP used for 
packet, */
+                                   /*      -1 use interface default */
+
 /* to define items, should talk with KAME guys first, for *BSD compatibility */
 
 #define IPV6_RTHDR_LOOSE     0 /* this hop need not be a neighbor. XXX old 
spec */

Modified: stable/12/sys/netinet6/ip6_output.c
==============================================================================
--- stable/12/sys/netinet6/ip6_output.c Sat Oct 24 20:09:27 2020        
(r367016)
+++ stable/12/sys/netinet6/ip6_output.c Sat Oct 24 20:23:20 2020        
(r367017)
@@ -90,7 +90,9 @@ __FBSDID("$FreeBSD$");
 
 #include <net/if.h>
 #include <net/if_var.h>
+#include <net/if_vlan_var.h>
 #include <net/if_llatbl.h>
+#include <net/ethernet.h>
 #include <net/netisr.h>
 #include <net/route.h>
 #include <net/pfil.h>
@@ -344,6 +346,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt,
        struct in6_addr odst;
        u_char *nexthdrp;
        int error = 0;
+       int vlan_pcp = -1;
        struct in6_ifaddr *ia = NULL;
        u_long mtu;
        int alwaysfrag, dontfrag;
@@ -367,6 +370,9 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt,
                        m->m_pkthdr.flowid = inp->inp_flowid;
                        M_HASHTYPE_SET(m, inp->inp_flowtype);
                }
+               if ((inp->inp_flags2 & INP_2PCP_SET) != 0)
+                       vlan_pcp = (inp->inp_flags2 & INP_2PCP_MASK) >>
+                           INP_2PCP_SHIFT;
        }
 
 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
@@ -917,6 +923,8 @@ again:
        }
 
 passout:
+       if (vlan_pcp > -1)
+               EVL_APPLY_PRI(m, vlan_pcp);
        /*
         * Send the packet to the outgoing interface.
         * If necessary, do IPv6 fragmentation before sending.
@@ -1110,6 +1118,8 @@ sendorfree:
                                m->m_pkthdr.snd_tag = NULL;
                        }
 #endif
+                       if (vlan_pcp > -1)
+                               EVL_APPLY_PRI(m, vlan_pcp);
                        error = nd6_output_ifp(ifp, origifp, m, dst,
                            (struct route *)ro);
 #ifdef RATELIMIT
@@ -1600,6 +1610,7 @@ ip6_ctloutput(struct socket *so, struct sockopt *sopt)
 #ifdef RSS
                        case IPV6_RSS_LISTEN_BUCKET:
 #endif
+                       case IPV6_VLAN_PCP:
                                if (optname == IPV6_BINDANY && td != NULL) {
                                        error = priv_check(td,
                                            PRIV_NETINET_BINDANY);
@@ -1791,6 +1802,29 @@ do {                                                     
                \
                                        }
                                        break;
 #endif
+                               case IPV6_VLAN_PCP:
+                                       if ((optval >= -1) && (optval <=
+                                           (INP_2PCP_MASK >> INP_2PCP_SHIFT))) 
{
+                                               if (optval == -1) {
+                                                       INP_WLOCK(inp);
+                                                       inp->inp_flags2 &=
+                                                           ~(INP_2PCP_SET |
+                                                           INP_2PCP_MASK);
+                                                       INP_WUNLOCK(inp);
+                                               } else {
+                                                       INP_WLOCK(inp);
+                                                       inp->inp_flags2 |=
+                                                           INP_2PCP_SET;
+                                                       inp->inp_flags2 &=
+                                                           ~INP_2PCP_MASK;
+                                                       inp->inp_flags2 |=
+                                                           optval <<
+                                                           INP_2PCP_SHIFT;
+                                                       INP_WUNLOCK(inp);
+                                               }
+                                       } else
+                                               error = EINVAL;
+                                       break;
                                }
                                break;
 
@@ -2015,6 +2049,7 @@ do {                                                      
                \
                        case IPV6_RECVRSSBUCKETID:
 #endif
                        case IPV6_BINDMULTI:
+                       case IPV6_VLAN_PCP:
                                switch (optname) {
 
                                case IPV6_RECVHOPOPTS:
@@ -2113,7 +2148,17 @@ do {                                                     
                \
                                        optval = OPTBIT2(INP_BINDMULTI);
                                        break;
 
+                               case IPV6_VLAN_PCP:
+                                       if (OPTBIT2(INP_2PCP_SET)) {
+                                               optval = (inp->inp_flags2 &
+                                                           INP_2PCP_MASK) >>
+                                                           INP_2PCP_SHIFT;
+                                       } else {
+                                               optval = -1;
+                                       }
+                                       break;
                                }
+
                                if (error)
                                        break;
                                error = sooptcopyout(sopt, &optval,
_______________________________________________
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