git: 22c81cc51636 - main - tcp: add AccECN CE packet counters to tcpinfo

From: Richard Scheffenegger <rscheff_at_FreeBSD.org>
Date: Sun, 06 Nov 2022 11:02:58 UTC
The branch main has been updated by rscheff:

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

commit 22c81cc51636cfebe94e0979eb31556d87775938
Author:     Richard Scheffenegger <rscheff@FreeBSD.org>
AuthorDate: 2022-11-06 10:55:52 +0000
Commit:     Richard Scheffenegger <rscheff@FreeBSD.org>
CommitDate: 2022-11-06 10:56:02 +0000

    tcp: add AccECN CE packet counters to tcpinfo
    
    Provide diagnostics information around AccECN into
    the tcpinfo struct.
    
    Event:                  IETF 115 Hackathon
    Reviewed By:            tuexen, #transport
    Sponsored by:           NetApp, Inc.
    Differential Revision:  https://reviews.freebsd.org/D37280
---
 sys/netinet/tcp.h        |  3 ++-
 sys/netinet/tcp_ecn.c    |  4 +++-
 sys/netinet/tcp_usrreq.c | 13 +++++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/sys/netinet/tcp.h b/sys/netinet/tcp.h
index 7bb2efe5fae0..aa7f73f8be3c 100644
--- a/sys/netinet/tcp.h
+++ b/sys/netinet/tcp.h
@@ -390,7 +390,8 @@ struct tcp_info {
 	u_int32_t	tcpi_snd_zerowin;	/* Zero-sized windows sent */
 
 	/* Accurate ECN counters. */
-	u_int32_t	__tcpi_received_ce;		/* # of CE marks received */
+	u_int32_t	tcpi_delivered_ce;
+	u_int32_t	tcpi_received_ce;		/* # of CE marks received */
 	u_int32_t	__tcpi_delivered_e1_bytes;
 	u_int32_t	__tcpi_delivered_e0_bytes;
 	u_int32_t	__tcpi_delivered_ce_bytes;
diff --git a/sys/netinet/tcp_ecn.c b/sys/netinet/tcp_ecn.c
index c74f4fa7c514..1d693944ac40 100644
--- a/sys/netinet/tcp_ecn.c
+++ b/sys/netinet/tcp_ecn.c
@@ -325,8 +325,10 @@ tcp_ecn_input_segment(struct tcpcb *tp, uint16_t thflags, int iptos)
 			}
 		} else {
 			/* RFC3168 ECN handling */
-			if ((thflags & (TH_SYN | TH_ECE)) == TH_ECE)
+			if ((thflags & (TH_SYN | TH_ECE)) == TH_ECE) {
 				delta_ace = 1;
+				tp->t_scep++;
+			}
 			if (thflags & TH_CWR) {
 				tp->t_flags2 &= ~TF2_ECN_SND_ECE;
 				tp->t_flags |= TF_ACKNOW;
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index d069c804bcc4..cc85c852ab6a 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -1640,6 +1640,19 @@ tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
 		tcp_offload_tcp_info(tp, ti);
 	}
 #endif
+	/*
+	 * AccECN related counters.
+	 */
+	if ((tp->t_flags2 & (TF2_ECN_PERMIT | TF2_ACE_PERMIT)) ==
+	    (TF2_ECN_PERMIT | TF2_ACE_PERMIT))
+		/*
+		 * Internal counter starts at 5 for AccECN
+		 * but 0 for RFC3168 ECN.
+		 */
+		ti->tcpi_delivered_ce = tp->t_scep - 5;
+	else
+		ti->tcpi_delivered_ce = tp->t_scep;
+	ti->tcpi_received_ce = tp->t_rcep;
 }
 
 /*