Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Mar 2021 19:57:05 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: bb4a7d94b99f - main - net: Introduce IPV6_DSCP(), IPV6_ECN() and IPV6_TRAFFIC_CLASS() macros
Message-ID:  <202103041957.124Jv5FZ027864@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=bb4a7d94b99fbf7f59c876ffff8ded5f6a5b5c3e

commit bb4a7d94b99fbf7f59c876ffff8ded5f6a5b5c3e
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2021-03-04 10:26:40 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-03-04 19:56:48 +0000

    net: Introduce IPV6_DSCP(), IPV6_ECN() and IPV6_TRAFFIC_CLASS() macros
    
    Introduce convenience macros to retrieve the DSCP, ECN or traffic class
    bits from an IPv6 header.
    
    Use them where appropriate.
    
    Reviewed by:    ae (previous version), rscheff, tuexen, rgrimes
    MFC after:      2 weeks
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D29056
---
 sys/net/altq/altq_subr.c                 | 2 +-
 sys/net/if_stf.c                         | 4 ++--
 sys/netinet/ip6.h                        | 4 ++++
 sys/netinet/tcp_input.c                  | 2 +-
 sys/netinet/tcp_lro.c                    | 2 +-
 sys/netinet/tcp_stacks/rack_bbr_common.c | 2 +-
 sys/netinet6/frag6.c                     | 5 ++---
 sys/netinet6/in6_gif.c                   | 2 +-
 sys/netinet6/ip6_output.c                | 4 ++--
 sys/netinet6/sctp6_usrreq.c              | 2 +-
 sys/netpfil/pf/pf.c                      | 2 +-
 11 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/sys/net/altq/altq_subr.c b/sys/net/altq/altq_subr.c
index 14d9916011da..39f91c4daf63 100644
--- a/sys/net/altq/altq_subr.c
+++ b/sys/net/altq/altq_subr.c
@@ -1087,7 +1087,7 @@ altq_extractflow(m, af, flow, filt_bmask)
 		fin6->fi6_family = AF_INET6;
 
 		fin6->fi6_proto = ip6->ip6_nxt;
-		fin6->fi6_tclass   = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
+		fin6->fi6_tclass   = IPV6_TRAFFIC_CLASS(ip6);
 
 		fin6->fi6_flowlabel = ip6->ip6_flow & htonl(0x000fffff);
 		fin6->fi6_src = ip6->ip6_src;
diff --git a/sys/net/if_stf.c b/sys/net/if_stf.c
index c3f26db3f6e6..40f8a6f3a30a 100644
--- a/sys/net/if_stf.c
+++ b/sys/net/if_stf.c
@@ -455,7 +455,7 @@ stf_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
 		}
 	}
 	ip6 = mtod(m, struct ip6_hdr *);
-	tos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
+	tos = IPV6_TRAFFIC_CLASS(ip6);
 
 	/*
 	 * Pickup the right outer dst addr from the list of candidates.
@@ -665,7 +665,7 @@ in_stf_input(struct mbuf *m, int off, int proto, void *arg)
 		return (IPPROTO_DONE);
 	}
 
-	itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
+	itos = IPV6_TRAFFIC_CLASS(ip6);
 	if ((ifp->if_flags & IFF_LINK1) != 0)
 		ip_ecn_egress(ECN_ALLOWED, &otos, &itos);
 	else
diff --git a/sys/netinet/ip6.h b/sys/netinet/ip6.h
index 44c46fd3b71d..1bc79a98e689 100644
--- a/sys/netinet/ip6.h
+++ b/sys/netinet/ip6.h
@@ -106,6 +106,10 @@ struct ip6_hdr {
 #endif
 #define IPV6_FLOWLABEL_LEN	20
 
+#define	IPV6_TRAFFIC_CLASS(ip6)	((ntohl((ip6)->ip6_flow) >> 20) & 0xff)
+#define	IPV6_DSCP(ip6)		((ntohl((ip6)->ip6_flow) >> 20) & 0xfc)
+#define	IPV6_ECN(ip6)		((ntohl((ip6)->ip6_flow) >> 20) & 0x03)
+
 /*
  * Extension Headers
  */
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index eda41d36ab88..89e70df48774 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -688,7 +688,7 @@ tcp_input(struct mbuf **mp, int *offp, int proto)
 			/* XXX stat */
 			goto drop;
 		}
-		iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
+		iptos = IPV6_TRAFFIC_CLASS(ip6);
 	}
 #endif
 #if defined(INET) && defined(INET6)
diff --git a/sys/netinet/tcp_lro.c b/sys/netinet/tcp_lro.c
index b4d64b8a6893..62f6ad57c0f5 100644
--- a/sys/netinet/tcp_lro.c
+++ b/sys/netinet/tcp_lro.c
@@ -1546,7 +1546,7 @@ tcp_lro_rx2(struct lro_ctrl *lc, struct mbuf *m, uint32_t csum, int use_hash)
 			return (error);
 		tcp_data_len = ntohs(ip6->ip6_plen);
 #ifdef TCPHPTS
-		iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
+		iptos = IPV6_TRAFFIC_CLASS(ip6);
 #endif
 		ip_len = sizeof(*ip6) + tcp_data_len;
 		break;
diff --git a/sys/netinet/tcp_stacks/rack_bbr_common.c b/sys/netinet/tcp_stacks/rack_bbr_common.c
index e73a3e60fd64..b86a5d85fc76 100644
--- a/sys/netinet/tcp_stacks/rack_bbr_common.c
+++ b/sys/netinet/tcp_stacks/rack_bbr_common.c
@@ -334,7 +334,7 @@ skip_vnet:
 				m_freem(m);
 				goto skipped_pkt;
 			}
-			iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
+			iptos = IPV6_TRAFFIC_CLASS(ip6);
 			break;
 		}
 #endif
diff --git a/sys/netinet6/frag6.c b/sys/netinet6/frag6.c
index f227930743b7..1903b01e03d4 100644
--- a/sys/netinet6/frag6.c
+++ b/sys/netinet6/frag6.c
@@ -554,8 +554,7 @@ frag6_input(struct mbuf **mp, int *offp, int proto)
 		q6->ip6q_ttl	= IPV6_FRAGTTL;
 		q6->ip6q_src	= ip6->ip6_src;
 		q6->ip6q_dst	= ip6->ip6_dst;
-		q6->ip6q_ecn	=
-		    (ntohl(ip6->ip6_flow) >> 20) & IPTOS_ECN_MASK;
+		q6->ip6q_ecn	= IPV6_ECN(ip6);
 		q6->ip6q_unfrglen = -1;	/* The 1st fragment has not arrived. */
 
 		/* Add the fragemented packet to the bucket. */
@@ -688,7 +687,7 @@ frag6_input(struct mbuf **mp, int *offp, int proto)
 	 * if CE is set, do not lose CE.
 	 * Drop if CE and not-ECT are mixed for the same packet.
 	 */
-	ecn = (ntohl(ip6->ip6_flow) >> 20) & IPTOS_ECN_MASK;
+	ecn = IPV6_ECN(ip6);
 	ecn0 = q6->ip6q_ecn;
 	if (ecn == IPTOS_ECN_CE) {
 		if (ecn0 == IPTOS_ECN_NOTECT) {
diff --git a/sys/netinet6/in6_gif.c b/sys/netinet6/in6_gif.c
index 33cc06d065b8..54cb81c6130f 100644
--- a/sys/netinet6/in6_gif.c
+++ b/sys/netinet6/in6_gif.c
@@ -344,7 +344,7 @@ in6_gif_input(struct mbuf *m, int off, int proto, void *arg)
 	gifp = GIF2IFP(sc);
 	if ((gifp->if_flags & IFF_UP) != 0) {
 		ip6 = mtod(m, struct ip6_hdr *);
-		ecn = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
+		ecn = IPV6_TRAFFIC_CLASS(ip6);
 		m_adj(m, off);
 		gif_input(m, gifp, proto, ecn);
 	} else {
diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c
index 58334788b05b..2b49a9f7c351 100644
--- a/sys/netinet6/ip6_output.c
+++ b/sys/netinet6/ip6_output.c
@@ -656,9 +656,9 @@ again:
 	if (opt && opt->ip6po_tclass >= 0) {
 		int mask = 0;
 
-		if ((ip6->ip6_flow & htonl(0xfc << 20)) == 0)
+		if (IPV6_DSCP(ip6) == 0)
 			mask |= 0xfc;
-		if ((ip6->ip6_flow & htonl(0x03 << 20)) == 0)
+		if (IPV6_ECN(ip6) == 0)
 			mask |= 0x03;
 		if (mask != 0)
 			ip6->ip6_flow |= htonl((opt->ip6po_tclass & mask) << 20);
diff --git a/sys/netinet6/sctp6_usrreq.c b/sys/netinet6/sctp6_usrreq.c
index b544d2975c6a..fcf15e4f81bf 100644
--- a/sys/netinet6/sctp6_usrreq.c
+++ b/sys/netinet6/sctp6_usrreq.c
@@ -141,7 +141,7 @@ sctp6_input_with_port(struct mbuf **i_pak, int *offp, uint16_t port)
 	if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
 		goto out;
 	}
-	ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
+	ecn_bits = IPV6_TRAFFIC_CLASS(ip6);
 	if (m->m_pkthdr.csum_flags & CSUM_SCTP_VALID) {
 		SCTP_STAT_INCR(sctps_recvhwcrc);
 		compute_crc = 0;
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index f71f89187b58..c131f810b0ec 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -6384,7 +6384,7 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb
 	pd.sidx = (dir == PF_IN) ? 0 : 1;
 	pd.didx = (dir == PF_IN) ? 1 : 0;
 	pd.af = AF_INET6;
-	pd.tos = (ntohl(h->ip6_flow) >> 20) & 0xfc;
+	pd.tos = IPV6_DSCP(h);
 	pd.tot_len = ntohs(h->ip6_plen) + sizeof(struct ip6_hdr);
 
 	off = ((caddr_t)h - m->m_data) + sizeof(struct ip6_hdr);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103041957.124Jv5FZ027864>