From owner-svn-src-head@freebsd.org Fri Oct 9 12:06:45 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6B0E93F8B5E; Fri, 9 Oct 2020 12:06:45 +0000 (UTC) (envelope-from rscheff@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4C76Hn25vfz4Jc1; Fri, 9 Oct 2020 12:06:45 +0000 (UTC) (envelope-from rscheff@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2CB1C190FD; Fri, 9 Oct 2020 12:06:45 +0000 (UTC) (envelope-from rscheff@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 099C6jDD025010; Fri, 9 Oct 2020 12:06:45 GMT (envelope-from rscheff@FreeBSD.org) Received: (from rscheff@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 099C6hPe025004; Fri, 9 Oct 2020 12:06:43 GMT (envelope-from rscheff@FreeBSD.org) Message-Id: <202010091206.099C6hPe025004@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rscheff set sender to rscheff@FreeBSD.org using -f From: Richard Scheffenegger Date: Fri, 9 Oct 2020 12:06:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366569 - in head/sys: net netinet netinet6 X-SVN-Group: head X-SVN-Commit-Author: rscheff X-SVN-Commit-Paths: in head/sys: net netinet netinet6 X-SVN-Commit-Revision: 366569 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Oct 2020 12:06:45 -0000 Author: rscheff Date: Fri Oct 9 12:06:43 2020 New Revision: 366569 URL: https://svnweb.freebsd.org/changeset/base/366569 Log: 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: head/sys/net/if_ethersubr.c head/sys/netinet/in.h head/sys/netinet/in_pcb.h head/sys/netinet/ip_output.c head/sys/netinet6/in6.h head/sys/netinet6/ip6_output.c Modified: head/sys/net/if_ethersubr.c ============================================================================== --- head/sys/net/if_ethersubr.c Fri Oct 9 11:24:19 2020 (r366568) +++ head/sys/net/if_ethersubr.c Fri Oct 9 12:06:43 2020 (r366569) @@ -1388,6 +1388,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: head/sys/netinet/in.h ============================================================================== --- head/sys/netinet/in.h Fri Oct 9 11:24:19 2020 (r366568) +++ head/sys/netinet/in.h Fri Oct 9 12:06:43 2020 (r366569) @@ -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: head/sys/netinet/in_pcb.h ============================================================================== --- head/sys/netinet/in_pcb.h Fri Oct 9 11:24:19 2020 (r366568) +++ head/sys/netinet/in_pcb.h Fri Oct 9 12:06:43 2020 (r366569) @@ -748,6 +748,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: head/sys/netinet/ip_output.c ============================================================================== --- head/sys/netinet/ip_output.c Fri Oct 9 11:24:19 2020 (r366568) +++ head/sys/netinet/ip_output.c Fri Oct 9 12:06:43 2020 (r366569) @@ -62,7 +62,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include +#include #include #include #include @@ -324,6 +326,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct rou int hlen = sizeof (struct ip); int mtu = 0; int error = 0; + int vlan_pcp = -1; struct sockaddr_in *dst, sin; const struct sockaddr_in *gw; struct in_ifaddr *ia = NULL; @@ -345,6 +348,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; #ifdef NUMA m->m_pkthdr.numa_domain = inp->inp_numa_domain; #endif @@ -717,6 +723,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))) { @@ -1210,6 +1219,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) @@ -1305,6 +1315,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 @@ -1425,6 +1457,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: optval = inp->inp_ip_tos; @@ -1511,6 +1544,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: head/sys/netinet6/in6.h ============================================================================== --- head/sys/netinet6/in6.h Fri Oct 9 11:24:19 2020 (r366568) +++ head/sys/netinet6/in6.h Fri Oct 9 12:06:43 2020 (r366569) @@ -511,6 +511,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: head/sys/netinet6/ip6_output.c ============================================================================== --- head/sys/netinet6/ip6_output.c Fri Oct 9 11:24:19 2020 (r366568) +++ head/sys/netinet6/ip6_output.c Fri Oct 9 12:06:43 2020 (r366569) @@ -92,7 +92,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include +#include #include #include #include @@ -436,6 +438,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, u_char *nexthdrp; int tlen, len; int error = 0; + int vlan_pcp = -1; struct in6_ifaddr *ia = NULL; u_long mtu; int alwaysfrag, dontfrag; @@ -460,6 +463,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; #ifdef NUMA m->m_pkthdr.numa_domain = inp->inp_numa_domain; #endif @@ -1098,6 +1104,8 @@ nonh6lookup: } 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. @@ -1265,6 +1273,8 @@ sendorfree: counter_u64_add(ia->ia_ifa.ifa_obytes, m->m_pkthdr.len); } + if (vlan_pcp > -1) + EVL_APPLY_PRI(m, vlan_pcp); error = ip6_output_send(inp, ifp, origifp, m, dst, ro, true); } else @@ -1752,6 +1762,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); @@ -1945,6 +1956,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; @@ -2168,6 +2202,7 @@ do { \ case IPV6_RECVRSSBUCKETID: #endif case IPV6_BINDMULTI: + case IPV6_VLAN_PCP: switch (optname) { case IPV6_RECVHOPOPTS: optval = OPTBIT(IN6P_HOPOPTS); @@ -2264,7 +2299,18 @@ do { \ case IPV6_BINDMULTI: 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,