git: 2169f71277b4 - main - tcp: use IPV6_FLOWLABEL_LEN

From: Richard Scheffenegger <rscheff_at_FreeBSD.org>
Date: Tue, 11 Apr 2023 17:23:27 UTC
The branch main has been updated by rscheff:

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

commit 2169f71277b4703606f97d2dfc703d1d0e2c9c9e
Author:     Richard Scheffenegger <rscheff@FreeBSD.org>
AuthorDate: 2023-04-11 16:53:20 +0000
Commit:     Richard Scheffenegger <rscheff@FreeBSD.org>
CommitDate: 2023-04-11 16:53:51 +0000

    tcp: use IPV6_FLOWLABEL_LEN
    
    Avoid magic numbers when handling the IPv6 flow ID for
    DSCP and ECN fields and use the named variable instead.
    
    Reviewed By:            tuexen, #transport
    Sponsored by:           NetApp, Inc.
    Differential Revision:  https://reviews.freebsd.org/D39503
---
 sys/netinet/ip6.h          | 6 +++---
 sys/netinet/tcp_output.c   | 4 ++--
 sys/netinet/tcp_subr.c     | 2 +-
 sys/netinet/tcp_syncache.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/sys/netinet/ip6.h b/sys/netinet/ip6.h
index 1bc79a98e689..6617e1ca7d00 100644
--- a/sys/netinet/ip6.h
+++ b/sys/netinet/ip6.h
@@ -106,9 +106,9 @@ 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)
+#define	IPV6_TRAFFIC_CLASS(ip6)	((ntohl((ip6)->ip6_flow) >> IPV6_FLOWLABEL_LEN) & 0xff)
+#define	IPV6_DSCP(ip6)		((ntohl((ip6)->ip6_flow) >> IPV6_FLOWLABEL_LEN) & 0xfc)
+#define	IPV6_ECN(ip6)		((ntohl((ip6)->ip6_flow) >> IPV6_FLOWLABEL_LEN) & 0x03)
 
 /*
  * Extension Headers
diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c
index 09036d940815..abfab1a62176 100644
--- a/sys/netinet/tcp_output.c
+++ b/sys/netinet/tcp_output.c
@@ -1204,8 +1204,8 @@ send:
 			tp->t_flags2 &= ~TF2_ECN_SND_ECE;
 #ifdef INET6
 		if (isipv6) {
-			ip6->ip6_flow &= ~htonl(IPTOS_ECN_MASK << 20);
-			ip6->ip6_flow |= htonl(ect << 20);
+			ip6->ip6_flow &= ~htonl(IPTOS_ECN_MASK << IPV6_FLOWLABEL_LEN);
+			ip6->ip6_flow |= htonl(ect << IPV6_FLOWLABEL_LEN);
 		}
 		else
 #endif
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 80202bc3a416..36112a101fa8 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -2005,7 +2005,7 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
 			ulen = tlen - sizeof(struct ip6_hdr);
 			uh->uh_ulen = htons(ulen);
 		}
-		ip6->ip6_flow = htonl(ect << 20);
+		ip6->ip6_flow = htonl(ect << IPV6_FLOWLABEL_LEN);
 		ip6->ip6_vfc = IPV6_VERSION;
 		if (port)
 			ip6->ip6_nxt = IPPROTO_UDP;
diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c
index 6a3561b179c2..96f57b9e0d95 100644
--- a/sys/netinet/tcp_syncache.c
+++ b/sys/netinet/tcp_syncache.c
@@ -1866,7 +1866,7 @@ syncache_respond(struct syncache *sc, const struct mbuf *m0, int flags)
 			ip6->ip6_nxt = IPPROTO_TCP;
 			th = (struct tcphdr *)(ip6 + 1);
 		}
-		ip6->ip6_flow |= htonl(sc->sc_ip_tos << 20);
+		ip6->ip6_flow |= htonl(sc->sc_ip_tos << IPV6_FLOWLABEL_LEN);
 	}
 #endif
 #if defined(INET6) && defined(INET)