aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Scheffenegger <rscheff@FreeBSD.org>2023-04-11 16:53:20 +0000
committerRichard Scheffenegger <rscheff@FreeBSD.org>2023-04-11 16:53:51 +0000
commit2169f71277b4703606f97d2dfc703d1d0e2c9c9e (patch)
treedf7d5ec0fe525e27f94470a80f8a45f47f1e64c8
parentaf7624ed314574d6da1eb45b9fddbd2ad503fea4 (diff)
downloadsrc-2169f71277b4703606f97d2dfc703d1d0e2c9c9e.tar.gz
src-2169f71277b4703606f97d2dfc703d1d0e2c9c9e.zip
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
-rw-r--r--sys/netinet/ip6.h6
-rw-r--r--sys/netinet/tcp_output.c4
-rw-r--r--sys/netinet/tcp_subr.c2
-rw-r--r--sys/netinet/tcp_syncache.c2
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)